﻿Imports System.ServiceModel
Imports System.Threading

Module Module1
    Public Delegate Function PunteroFuncion() As String
    Sub Main()


        Dim f As New Form1
        f.ShowDialog()


        Dim del As PunteroFuncion
        del = New PunteroFuncion(AddressOf Dowork)

        Dim cb As New AsyncCallback(AddressOf OnFinish)


        Dim resul As IAsyncResult = _
            del.BeginInvoke(cb, del)


        Console.WriteLine("haciendo otra cosa")


        'While (Not resul.IsCompleted)
        '    Console.WriteLine("esperando ....")
        '    Thread.Sleep(1000)
        'End While

        'resul.AsyncWaitHandle.WaitOne()

        Console.ReadLine()
    End Sub
    Public Function Dowork() As String
        Dim bs As New BasicHttpBinding
        Dim ea As New EndpointAddress("http://localhost:1053/WebSite1/Service.svc")
        Dim proxy = ChannelFactory(Of CustomProxy.ServiceProxy.IService).CreateChannel(bs, ea)


        Return proxy.DoWork
    End Function

    Public Sub OnFinish(ByVal result As IAsyncResult)
        Dim del As PunteroFuncion = CType(result.AsyncState, PunteroFuncion)
        Dim mensaje = del.EndInvoke(result)
        Console.WriteLine(mensaje)
    End Sub

End Module
